
var biz = {};
biz.titf = {}
biz.titf.package ={};

biz.titf.package ={
    showHover: function(e, url) {
	e.style.backgroundColor="#f2f2f2";
	e.style.color="#5073b9";
	var cc = document.getElementById("center_col");
	var previewEle = document.createElement('div');
	previewEle.style.backgroundColor="#eeeeee";
	previewEle.style.position="absolute";
	var absTop = 0;
	var margin = document.getElementById("sfcnt").offsetHeight + document.getElementById("sfcnt").offsetTop + document.getElementById("gog").offsetHeight + document.getElementById("gog").offsetTop;
	if (document.body.scrollTop > cc.offsetTop){
	    absTop = document.body.scrollTop - margin
	}else{
	    absTop = document.body.scrollTop;
	}
	previewEle.style.top  = absTop + "px";
	previewEle.style.left = (cc.offsetLeft + cc.offsetWidth - 20) + "px";
	previewEle.style.color="#000000";
	bw = document.getElementById("gsr").offsetWidth;
	previewEle.style.width = (bw - (cc.offsetLeft + cc.offsetWidth) + 20) + "px";
	previewEle.style.float = "right";
	previewEle.innerHTML   = '<img src="'+ chrome.extension.getURL("/loading.gif")+ '" width=66 height=66 />';
	previewEle.style.height = (window.innerHeight - 8) + "px";
	previewEle.style.lineHeight = (window.innerHeight - 8) + "px";
	previewEle.style.textAlign  = "center";
	previewEle.id    = "previewEle";
	cc.appendChild(previewEle);
	this.getPreview(url);
    },
    hideHover: function(e, url) {
	e.style.backgroundColor="#f8f8f8";
	e.style.color="#d9d9d9";
	var cc = document.getElementById("center_col");
	cc.removeChild(document.getElementById("previewEle"));
    },
    getPreview: function(url) {
	chrome.extension.sendRequest({'action' : 'getPreview', "url": url}, this.showPreview);
    },
    showPreview: function(data){
        previewEle = document.getElementById("previewEle");
	previewEle.style.textAlign  = "left";
        previewEle.style.lineHeight = "1.3em";
        previewEle.style.width   = (previewEle.offsetWidth - 10) + "px";
        previewEle.style.padding = "5px";
	previewEle.innerHTML = data;
    }
    
}

var res = document.getElementsByTagName("li");


for(var i = 0; i < res.length; i++){
    if (res[i].className   == "g w0") {
	var childEle = res[i].childNodes;
	for(var j = 0; j < childEle.length; j++){
	    var l = "";
	    if (childEle[j].tagName == "H3"){
		anchor = childEle[j].childNodes[0];
		l = anchor.getAttribute("href");
		var titleEle = childEle[j];
	    }
	    if (childEle[j].className == "r"){
		var ele = document.createElement('div');
		ele.style.backgroundColor="#f8f8f8";
		ele.style.color="#d9d9d9";
		ele.style.width = "20px";
		ele.style.float = "right";
		ele.innerHTML   = "&gt;";
		ele.style.height = res[i].offsetHeight + "px";
		ele.style.lineHeight = res[i].offsetHeight + "px";
		ele.style.textAlign    = "center";

		ele.url = l;
		ele.onmouseover = function(){(biz.titf.package.showHover(this, this.url))};
		ele.onmouseout  = function(){(biz.titf.package.hideHover(this, this.url))};
	    }
	    
	}
	res[i].insertBefore(ele , titleEle);
    }
}


